﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DQYT.HTDZ.BLL;
using System.Data;

namespace SkWeb.FYCS
{
    public partial class TB_DDJList : System.Web.UI.Page
    {
        #region 事件处理程序

        //页面加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    lblPath.Text = "费用预算 >> 弹型维护";
                    InitData("");
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message.ToString();
            }
        }

        //列表行绑定事件
        protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //如果没有数据则添加一行“没有数据”行
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string sRow = e.Row.Cells[2].Text.Trim().ToString().Replace("&nbsp;", "");
                    if (string.IsNullOrEmpty(sRow))
                    {
                        return;
                    }
                    string ProNum = DataBinder.Eval(e.Row.DataItem, "BUM_RS").ToString();

                    if (Convert.ToInt32(ProNum) > 0)
                    {

                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }

        }

        //添加按钮点击事件
        protected void btnAdd_Click(object sender, EventArgs e)
        {

            Response.Redirect("TB_DDJEdit.aspx?action=add");

        }

        //列表行事件
        protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                TB_DDJBLL BLL = new TB_DDJBLL();
                if (e.CommandName == "DeleteRow")
                {
                    if (BLL.Delete(int.Parse(e.CommandArgument.ToString())))
                    {
                        InitData("");
                    }
                }
                if (e.CommandName == "EditRow")
                {
                    string id = e.CommandArgument.ToString();
                    Response.Redirect("TB_DDJEdit.aspx?id=" + id + "&action=update");
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message;
            }
        }


        #endregion 事件处理程序

        #region 函数集

        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitData(string strWhere)
        {
            DataTable dt = new DataTable();
            TB_DDJBLL BLL = new TB_DDJBLL();
            dt = BLL.GetList(strWhere).Tables[0];
            if (dt == null || dt.Rows.Count < 1)
            {
                dt.Rows.Add(dt.NewRow());
            }

            gvData.DataSource = dt;
            gvData.DataKeyNames = new string[] { "ID" };
            gvData.Columns[0].Visible = false;
            gvData.DataBind();
        }

        #endregion 函数集
    }
}